#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
void Worker()
{
  int cnt=12;
  while(cnt)
  {
    printf("子进程%d正在跑%d\n",getpid(),cnt);
    cnt--;
    sleep(1);
  }
}
int main()
{
for(int i=0;i<10;i++)
{
  pid_t id = fork();
  if(id<0)break;
  if(id==0)
  {//子进程
      Worker();
      exit(0);
  }
  printf("父进程成功创建子进程，子进程pid是%d\n",id);
  sleep(1);
}
sleep(15);
  return 0;
}

//int main()
//{
//for(int i=1;i<100;i++)
//{
//  printf("i ");
//}
//  return 0;
//}
//int main()
//{
//printf("befork fork,I am a process pid is %d,ppid is %d\n",getpid(),getppid());
//sleep(2);
//printf("开始创建进程了\n");
//sleep(2);
//pid_t id=fork();
//if(id<0)return 1;
//else if(id==0)
//{//子进程
//  printf("我是子进程 pid is %d,ppid is %d\n",getpid(),getppid());
//  sleep(1);
//}
//else
//{
//  printf("我是父进程 pid is %d,ppid is %d\n",getpid(),getppid());
//  sleep(1);
//}
//sleep(2);
//  return 0;
//}
//

//int main()
//{
//printf("befork fork,I am a process pid is %d,ppid is %d\n",getpid(),getppid());
//fork();
//printf("after fork,I am a process pid is %d,ppid is %d\n",getpid(),getppid());
//sleep(2);
//  return 0;
//}
